package cn.com.guage.guc.juc;

import java.util.concurrent.CountDownLatch;

import cn.com.guage.guc.enume.CountDownLatchEnum;

public class CountDownLatchDemo2 {

	 public static void main(String[] args) throws InterruptedException {
	        CountDownLatch count = new CountDownLatch(6);
	        for (int i = 1; i <= 6; i++) {
	            new Thread(() -> {
	                System.out.println(Thread.currentThread().getName() + "\t 国，被灭");
	                count.countDown();//逐个减一，只有所有的线程执行完成，才会执行下面的代码(倒计数 )
	            }, CountDownLatchEnum.getMessenger(i).getRetMessenger()).start();
	        }
	        count.await();//判断上面的线程是否执行完成，若未完成；则返回上面继续执行，直到上面的线程执行完成，才会执行下面的代码
	        System.out.println(Thread.currentThread().getName().replaceAll("main","秦") + "\t 国，统一六国");
	    }
}
